package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.pojo.User;
import com.neuedu.mapper.UserMapper;
import com.neuedu.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangle
 * @since 2020-09-16
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    BCryptPasswordEncoder encoder;

    @Override
    public User token(User user) {
        //先查用户名
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",user.getUsername());

        User user1 = this.getOne(wrapper);
        if(user!= null){
         if( encoder.matches(user.getPassword(),user1.getPassword())){
             return  user;
         }
        }
        return null;
    }
}
